package com.apes.framework.plugin.scheduler;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextClosedEvent;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.stereotype.Component;

/**
 * 功能：线程池优雅停机
 *
 * @author xul
 * @create 2018-03-19 17:56
 */
@Component
public class ScheduleClosedHandler implements ApplicationListener<ContextClosedEvent> {

    @Autowired
    ThreadPoolTaskScheduler threadPoolTaskScheduler;

    @Override
    public void onApplicationEvent(ContextClosedEvent contextClosedEvent) {
        threadPoolTaskScheduler.shutdown();
    }
}
